// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Lava Geyser Object
// Script Author: Christan Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 65 : TYPE_LAVAGEYSER

// Function declarations
reserve function LavaGeyser_DebugDraw
reserve function LavaGeyser_DebugSpawn

// Static Values

// Tables

function LavaGeyser_DebugDraw
	DrawSprite(2)
end function


function LavaGeyser_DebugSpawn
	CreateTempObject(TypeName[Lava Geyser], 0, object.xpos, object.ypos)
	object[tempObjectPos].value1 = object.ypos
	object[tempObjectPos].drawOrder = 5
end function


event ObjectMain
	switch object.state
	case 0
		foreach (TypeName[Push Block], arrayPos0, ACTIVE_ENTITIES)
			BoxCollisionTest(C_TOUCH, arrayPos0, -16, -16, 16, 16, object.entityPos, -16, -32, 16, 16)
			if checkResult == 1
				object.state = 1
				object.animationTimer = 0
				object.value2 = 0
				object.value4 = 4
			end if
		next
		break
	case 1
		object.value4 = object.value2
		object.value4 /= 3
		object.value4 += 4
		object.value2++
		object.value2 %= 6
		object.value0++
		if object.value0 == 12
			object.value0 = 0
			object.state++
		end if
		break
	case 2
		object.value4 = object.value2
		object.value4 /= 3
		object.value4 += 6
		object.value2++
		object.value2 %= 6
		object.value0++
		if object.value0 == 12
			object.value0 = 0
			object.frame = 0
			object.value3 = 8
			object.yvel = -0x54000
			object.state++
			PlaySfx(SfxName[Fire Burn], 0)
			foreach (TypeName[Push Block], arrayPos0, ACTIVE_ENTITIES)
				BoxCollisionTest(C_TOUCH, arrayPos0, -16, -16, 16, 16, object.entityPos, -32, -32, 32, 16)
				if checkResult == 1
					object[arrayPos0].yvel = -0x59000
					object[arrayPos0].gravity = GRAVITY_AIR
				end if
			next
		end if
		break
	case 3
		object.yvel += 0x1800
		object.ypos += object.yvel
		if object.ypos >= object.value1
			object.ypos = object.value1
			object.state++
		end if
		object.value4 = object.value2
		object.value4 /= 3
		object.value3 = object.value4
		object.value4 += 2
		object.value3 += 8
		object.value2++
		object.value2 %= 6
		object.frame = object.animationTimer
		object.frame >>= 3
		object.animationTimer++
		object.animationTimer &= 15
		temp0 = object.value1
		temp0 -= object.ypos
		temp0 >>= 16
		foreach (GROUP_PLAYERS, currentPlayer, ACTIVE_ENTITIES)
			BoxCollisionTest(C_TOUCH, object.entityPos, -32, 0, 32, temp0, currentPlayer, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO, HITBOX_AUTO)
			if checkResult == 1
				CallFunction(PlayerObject_FireHit)
			end if
		next
		break
	case 4
		object.value4 = object.value2
		object.value4 /= 3
		object.value4 += 2
		object.value2++
		object.value2 %= 6
		object.value0++
		if object.value0 == 12
			object.value0 = 0
			object.state++
		end if
		break
	case 5
		object.value4 = object.value2
		object.value4 /= 3
		object.value4 += 4
		object.value2++
		object.value2 %= 6
		object.value0++
		if object.value0 == 12
			object.value0 = 0
			object.state = 0
		end if
		break
	end switch
end event


event ObjectDraw
	switch object.state
	case 1
	case 2
	case 4
	case 5
		DrawSpriteXY(object.value4, object.xpos, object.value1)
		break
	case 3
		temp0 = object.value1
		temp0 -= object.ypos
		temp0 >>= 16
		temp1 = temp0
		FlipSign(temp1)
		if object.frame == 0
			EditFrame(0, -32, temp1, 64, temp0, 317, 1)
		else
			EditFrame(1, -32, temp1, 64, temp0, 382, 1)
		end if
		DrawSpriteXY(object.frame, object.xpos, object.value1)
		DrawSprite(object.value3)
		DrawSpriteXY(object.value4, object.xpos, object.value1)
		break
	end switch
end event


event ObjectStartup
	LoadSpriteSheet("MZ/Objects.gif")
	SpriteFrame(-32, -128, 64, 256, 317, 1)
	SpriteFrame(-32, -128, 64, 256, 382, 1)
	SpriteFrame(-56, -18, 112, 30, 288, 332)
	SpriteFrame(-55, -18, 110, 30, 401, 332)
	SpriteFrame(-24, -18, 48, 30, 268, 1)
	SpriteFrame(-23, -18, 46, 30, 270, 32)
	SpriteFrame(-56, -22, 112, 34, 288, 297)
	SpriteFrame(-55, -22, 110, 34, 401, 297)
	SpriteFrame(-56, -26, 112, 38, 288, 258)
	SpriteFrame(-55, -26, 110, 38, 401, 258)
	foreach (TypeName[Lava Geyser], arrayPos0, ALL_ENTITIES)
		object[arrayPos0].value1 = object[arrayPos0].ypos
		object[arrayPos0].drawOrder = 5
	next
	SetTableValue(TypeName[Lava Geyser], DebugMode_ObjCount, DebugMode_TypesTable)
	SetTableValue(LavaGeyser_DebugDraw, DebugMode_ObjCount, DebugMode_DrawTable)
	SetTableValue(LavaGeyser_DebugSpawn, DebugMode_ObjCount, DebugMode_SpawnTable)
	DebugMode_ObjCount++
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
